package com.bstek.demo.test;

import com.bstek.demo.entity.PointsCard;
import com.bstek.urule.model.GeneralEntity;
import com.bstek.urule.model.library.action.annotation.ActionBean;
import com.bstek.urule.model.library.action.annotation.ActionMethod;
import com.bstek.urule.model.library.action.annotation.ActionMethodParameter;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Title: CarPointInfoAction
 * @Package: com.bstek.demo.test
 * @Description:
 * @Author: zxq
 * @Date: 2023/10/8 - 13:45
 */

@Component("carPointInfo")
@ActionBean(name="积分信息")
public class CarPointInfoAction {

    public static Map<String, PointsCard> card=new ConcurrentHashMap<>();

    @ActionMethod(name="获取积分信息")
    public PointsCard getPoint(GeneralEntity generalEntity){
        String cardId = (String) generalEntity.get("cardId");
        PointsCard entity = card.get(cardId);
        if (entity==null){
            PointsCard pointsCard = new PointsCard();
            pointsCard.setCardId(cardId);
            pointsCard.setCardSort(0);
            card.put(cardId,pointsCard);
            return pointsCard;
        }
        return entity;
    }

    @ActionMethod(name="更新积分信息")
    @ActionMethodParameter(names={"积分卡号","积分"})
    public PointsCard upPoint(String cardId,Integer cardSort){
        PointsCard entity = card.get(cardId);
        if (entity!=null){
            entity.setCardSort(cardSort);
        }

        card.put(cardId,entity);
        return entity;
    }



}
